﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.Infrastructure.CrossCutting.Logging;
using Cesave.Infrastructure.CrossCutting.IoC;
using Cesave.DistributedServices.Core.ErrorHandlers;
using System.ServiceModel;
using Cesave.Domain.PermisosModule.Contracts.Secciones;
using Cesave.Domain.PermisosModule.Entities;

namespace Cesave.DistributedServices.PermisosModule
{
	public partial class PermisosModuleService
	{
		#region IPermisosModuleService Members

		/// <summary>
		/// 
		/// </summary>
		/// <param name="seccion"></param>
		public void AddSeccion(Domain.PermisosModule.Entities.Seccion seccion)
		{
			try
			{
				ISeccionService seccionService = IoCFactory.Resolve<ISeccionService>();
				seccionService.AddSeccion(seccion);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="seccion"></param>
		public void ChangeSeccion(Domain.PermisosModule.Entities.Seccion seccion)
		{
			try
			{
				ISeccionService seccionService = IoCFactory.Resolve<ISeccionService>();
				seccionService.ChangeSeccion(seccion);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="moduloGuid"></param>
		/// <returns></returns>
		public List<Domain.PermisosModule.Entities.Seccion> FindSeccionesByModulo(Guid moduloGuid)
		{
			try
			{
				ISeccionService seccionService = IoCFactory.Resolve<ISeccionService>();
				return seccionService.FindSeccionesByModulo(moduloGuid);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="moduloGuid"></param>
		/// <param name="status"></param>
		/// <returns></returns>
		public List<Domain.PermisosModule.Entities.Seccion> FindSeccionesByModuloAndStatus(Guid moduloGuid, bool status = true)
		{
			try
			{
				ISeccionService seccionService = IoCFactory.Resolve<ISeccionService>();
				return seccionService.FindSeccionesByModuloAndStatus(moduloGuid, status);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

        /// <summary>
        /// 
        /// </summary>
        /// <param name="juntaGuid"></param>
        /// <returns></returns>
        public List<Domain.PermisosModule.Entities.Seccion> FindSeccionesByJunta(Guid juntaGuid)
        {
            try
            {
                ISeccionService seccionService = IoCFactory.Resolve<ISeccionService>();
                return seccionService.FindSeccionesByJunta(juntaGuid);
            }
            catch (Exception ex)
            {
                ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
                traceManager.TraceError(ex.Message);

                ServiceError detail = ServiceError.Factory(ex.Message);
                throw new FaultException<ServiceError>(detail);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="seccionGuid"></param>
        /// <returns></returns>
        public Seccion FindSeccionByGuid(Guid seccionGuid)
        {
            try
            {
                ISeccionService seccionService = IoCFactory.Resolve<ISeccionService>();
                return seccionService.FindSeccionByGuid(seccionGuid);
            }
            catch (Exception ex)
            {
                ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
                traceManager.TraceError(ex.Message);

                ServiceError detail = ServiceError.Factory(ex.Message);
                throw new FaultException<ServiceError>(detail);
            }
        }

        #endregion

    }
}
